package com.lmqb.controller;

import java.io.UnsupportedEncodingException;

import java.math.BigDecimal;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.lmqb.entry.MenuTitle;
import com.lmqb.bean.LmWithdraw;
import com.lmqb.bean.SysUser;
import com.lmqb.page.WithdrawPager;
import com.lmqb.service.CheckWithDrawService;
import com.lmqb.service.JiaoYanService;

/*
 * 体现审核
 * */
@Controller
public class CheckWithdrawController extends BaseController{
	
	@Autowired
	private JiaoYanService jiaoYanService;
   
	@Autowired
	private CheckWithDrawService checkWithDrawService;
	
	//进入提现审核页面
	@RequestMapping(value="checkwithdraw.html",method=RequestMethod.GET)
	public String checkWithDraw(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,WithdrawPager pagerModel){
		
		
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(WithdrawPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			pagerModel.setCheckStatus((byte)0);
			WithdrawPager userBankPager=checkWithDrawService.selectCheckWithdrawPager(pagerModel);
			setIfEndty(pagerModel);
			request.setAttribute(pager, userBankPager);
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("提现审核");
			menuTitle.setMenu("管理员审核");
			session.setAttribute(menuTitleF, menuTitle);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "checkWithDraw";
	}
	
	//审核通过
	@RequestMapping(value="checkSrtatusUpdatePass",method=RequestMethod.GET)
	public String checkSrtatusUpdatePass(String withdrawNo,BigDecimal withdrawMoney,BigDecimal withdrawFee,
			                              Integer userId,String userName,String bankNum,Integer creatTime,HttpServletRequest request) throws UnsupportedEncodingException{
		userName = new String(userName.getBytes("iso8859-1"),"utf-8");
		System.out.println("审核通过"+"-->"+withdrawNo+"-->"+withdrawMoney+"-->"+userId+"-->"+userName+"-->"+bankNum+"-->"+creatTime);
		checkWithDrawService.checkSrtatusUpdatePass(withdrawNo, withdrawMoney, withdrawFee, userId, userName,bankNum, creatTime);
		return "redirect:checkwithdraw.html";
	}
	
	   //审核不通过
		@RequestMapping(value="checkSrtatusUpdateNoPass",method=RequestMethod.GET)
		public String checkSrtatusUpdateNoPass(BigDecimal withdrawMoney,String withdrawNo,BigDecimal freeznMoney,
				                               BigDecimal balance,Integer userId
				){
			
			
			checkWithDrawService.checkSrtatusUpdateNoPass(withdrawMoney, withdrawNo, freeznMoney, balance,userId);
			
			
			return "redirect:checkwithdraw.html";
		}
}
